#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <sys/wait.h>
#include <string.h>
#include <stdlib.h>

int main()
{
	pid_t id=fork();
	if(id<0)
	{
		printf("strno:%d,errorstr:%s\n",errno,strerror(errno));	
		return errno;
	}
	else if(id==0)
	{
		int cnt=3;
		while(cnt)
		{
			printf("I am a child process,pid:%d,ppid:%d\n",getpid(),getppid());	
			cnt--;
			sleep(1);

		}
		exit(0);
	}
	else
	{
//`		sleep(6);
		pid_t rid=wait(NULL);
		if(rid>0)//成功，返回子进程pid
		{
			printf("wait success,rid:%d\n",rid);	
		}
		while(1){
			printf("I am a father process,pid:%d,ppid:%d\n",getpid(),getppid());	
			sleep(2);

		}
	}

	return 0;
}
